#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/string.hpp"

using namespace std::chrono_literals;

namespace pub_topic
{
    class topic_pub : public rclcpp::Node
    {
    private:
        rclcpp::Publisher<std_msgs::msg::String>::SharedPtr pub_;
        rclcpp::TimerBase::SharedPtr timer_;
        void timer_cb()
        {
            auto message = std_msgs::msg::String();
            message.data = "This is topic pub";
            RCLCPP_INFO(this->get_logger(),message.data.c_str());
            pub_->publish(message);
        }
    public:
        topic_pub(std::string name);
        ~topic_pub();
    };

   topic_pub::topic_pub(std::string name) : Node(name)
   {
        RCLCPP_INFO(this->get_logger(),"topic_pub");
        pub_ = this->create_publisher<std_msgs::msg::String>("/topic_pub",10);
        timer_ = this->create_wall_timer(500ms,std::bind(&topic_pub::timer_cb,this));
   }
   
   topic_pub::~topic_pub()
   {

   }
} // namespace pub_topic


int main(int argc, char **argv)
{
    rclcpp::init(argc,argv);
    auto node = std::make_shared<pub_topic::topic_pub>("topic_pub");
    rclcpp::spin(node);
    rclcpp::shutdown();
    return 0;
}
